package com.lyloou.practice.factory;

import com.lyloou.practice.pojo.Company;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author lyloou
 * @date 2020/05/31
 * @desc
 */
public class CompanyFactoryBean implements FactoryBean<Company> {
    String companyInfo;

    public void setCompanyInfo(String companyInfo) {
        this.companyInfo = companyInfo;
    }

    @Override
    public Company getObject() throws Exception {
        String[] data = companyInfo.split(",");
        Company company = new Company();
        company.setName(data[0]);
        company.setAddress(data[1]);
        company.setScale(Integer.parseInt(data[2]));
        return company;
    }

    @Override
    public Class<?> getObjectType() {
        return Company.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
